package com.wf.quartz;

import com.wf.constant.RedisConstant;
import com.wf.domain.ContractInfo;
import com.wf.service.ContractInfoService;
import com.wf.utils.RedisUtil;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author mpk
 * @since 2024/9/10 18:32:08
 */
@Component
public class DayViewQuartz  extends QuartzJobBean {


    @Autowired
    RedisUtil redisUtil;

    @Autowired
    ContractInfoService contractInfoService;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

        Set<String> keys = redisUtil.keys(RedisConstant.APARTMENT_HOUSE_VIEW_COUNT + "*");
        for (String key : keys) {
            Long num = Long.valueOf(redisUtil.get(key).toString());
            ContractInfo contractInfo = new ContractInfo();
            contractInfo.setContractId(Integer.parseInt(key.split("::")[4]));
            contractInfo.setViewDay(num);
            contractInfoService.updateById(contractInfo);

        }

    }
}


